﻿using System.Reflection;

namespace WenAntdUI.Helps
{
    public static class VersionHelp
    {
        public static string GetVersionString()
        {
            return $"{Version?.Major}.{Version?.Minor}";
        }

        public static string AppendVersion(this Control control)
        {
            var text = control.Text + " V." + GetVersionString();
            control.Text = text;
            return text;
        }

        public static Version Version => System.Reflection.Assembly.GetExecutingAssembly()?.GetName()?.Version;

        public static string GetVersionString(this System.Reflection.Assembly assembly)
        {
            var version = assembly?.GetName()?.Version;
            return version == null ? "" : $"{version.Major}.{version.Minor}.{version.Build}";
        }

        /// <summary>
        /// 取主程序集的 Assembly 对象
        /// </summary>
        public static Assembly MainAssembly = Assembly.GetEntryAssembly();

        /// <summary>
        /// 主程序版本
        /// </summary>
        public static Version MainVersion => MainAssembly?.GetName()?.Version ?? new Version(1, 0);
        /// <summary>
        /// 获取主程序版本号
        /// </summary>
        public static string MainVersionString => $"{MainVersion?.Major}.{MainVersion?.Minor}.{MainVersion?.Build}";
        /// <summary>
        /// 获取名称+版本号
        /// </summary>
        /// <returns></returns>
        public static string GetAppNameVersion(string? appname = null)
        {
            return $"{appname ?? "Senyun"} - V{MainVersionString}";
        }
    }
}
